package com.yiyuan.app.controller;

import com.guaike.core.entity.result.Result;
import com.yiyuan.app.entity.param.AuthRealNameDTO;
import com.yiyuan.app.entity.param.BindWxDTO;
import com.yiyuan.app.entity.param.IosLoginDTO;
import com.yiyuan.app.entity.param.WxLoginDTO;
import com.yiyuan.app.entity.result.AppUserVO;
import com.yiyuan.app.entity.result.ImageVO;
import com.yiyuan.app.entity.result.LoginUserVO;
import com.yiyuan.app.entity.result.VersionVO;
import com.yiyuan.app.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: zhangxilin
 * @Date: 2024/9/25
 */

@RestController
@RequestMapping("/login")
@Api(tags = "登录流程接口组")
@AllArgsConstructor
public class LoginController {

    private final LoginService loginService;

    @PostMapping("/wx/authLogin")
    @ApiOperation(value = "微信授权登录")
    public Result<AppUserVO> wxLogin(@Valid @RequestBody WxLoginDTO param) throws WxErrorException {
        return loginService.wxLogin(param);
    }

    @PostMapping("/ios/authLogin")
    @ApiOperation(value = "ios授权登录")
    public Result<LoginUserVO> iosLogin(@Valid @RequestBody IosLoginDTO param) {
        return loginService.iosLogin(param);
    }

    @PostMapping("/bindWx")
    @ApiOperation(value = "ios首次登录绑定微信")
    public Result<Boolean> bindWx(@Valid @RequestBody BindWxDTO param) throws WxErrorException {
        return loginService.bindWx(param);
    }

    @PostMapping("/authRealName")
    @ApiOperation(value = "实名认证")
    public Result<Boolean> authRealName(@Valid @RequestBody AuthRealNameDTO param) {
        return loginService.authRealName(param);
    }

    @PostMapping("/logout")
    @ApiOperation(value = "退出登录")
    public Result<Boolean> logout() {
        return loginService.logout();
    }

    @GetMapping("/startPage/list")
    @ApiOperation(value = "启动页列表")
    public Result<List<ImageVO>> startPage() {
        return loginService.startPage();
    }

    @GetMapping("/checkAppUpdate")
    @ApiOperation(value = "判断app是否需要更新")
    public Result<VersionVO> checkAppUpdate() {
        return loginService.checkAppUpdate();
    }
}
